
<template>
    <a-input-group compact>
          <VersionTypeSelect v-model="versionType" :disabled="disabled" class="version-type-select" :append-to-body="false"  style="width: 80px;" @change="changeVersionType"/>
          <a-select
            show-search
            option-filter-prop="children"
            :placeholder="$t('pleaseSelect') + $t('vehicleVersion').toLowerCase()"
            :filter-option="filterOption"
            :allow-clear="true"
            :mode="mode"
            :maxTagCount="1"
            :disabled="disabled"
            v-model="value"
            @change="changeOption"
            style="border-radius:0 4px 4px 0;"
            :style="{width: 'calc(100% - 80px)'}"
          >
            <a-select-option v-for="item in options" :key="item" :value="item">
              {{ item }}
            </a-select-option>
            </a-select>
     </a-input-group>
</template>
<script>
import vehicleVersionApi from '@/api/modules/software/vehicleVersion'
import VersionTypeSelect from './VersionTypeSelect'

import lodash from 'lodash'
export default {
  components:{VersionTypeSelect},
  props: {
    value: {
      type: String,
      default: ''
    },
    mode: {
      type: String,
      default: 'multiple'
    },
    time: {
      type: Number,
      default: 124578
    },
    disabled: {
      type: Boolean,
      default: false
    },
    query: {
      type: Object,
      default () {
        return null
      }
    }
  },
  data () {
    return {
      versionType: 'TEST',
      options: []
    }
  },
  computed: {
  },
  watch: {
    time: {
      handler (val) {
        if (val === 0) {
          return
        }
        this.getData()
      },
      immediate: true
    }
  },
  created () {
    this.$store.dispatch('getVersionTypeDictCodeData')
  },
  methods: {
    getData () {
      this.options = []
      vehicleVersionApi.getVehicleVersionNameSelect(this.query, this.versionType).then(res => {
        this.options = res.data
      })
    },
    changeOption (val) {
      this.$emit('changeoption', val)
    },
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    },
    changeVersionType(){
      this.getData ()
    }
  }
}
</script>
